Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_wallet_summary to WalletRead #914

Merged
merged 4 commits into from
Sep 6, 2023

Conversation

nuttycom
Copy link
Contributor

@nuttycom nuttycom commented Aug 24, 2023

No description provided.

Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1e5eae8

zcash_client_backend/src/data_api.rs Outdated Show resolved Hide resolved
zcash_client_backend/src/data_api.rs Outdated Show resolved Hide resolved
zcash_client_backend/src/data_api.rs Show resolved Hide resolved
zcash_client_backend/src/data_api.rs Show resolved Hide resolved
zcash_client_backend/src/data_api.rs Outdated Show resolved Hide resolved
zcash_client_sqlite/src/wallet/sapling.rs Outdated Show resolved Hide resolved
zcash_client_backend/src/data_api.rs Outdated Show resolved Hide resolved
@nuttycom nuttycom force-pushed the sbs/nonlinear_sync_aware_balance branch 5 times, most recently from 095971a to 19edc1c Compare September 1, 2023 18:36
@nuttycom nuttycom marked this pull request as ready for review September 1, 2023 18:49
@nuttycom nuttycom changed the title WIP: Add get_wallet_summary to WalletRead Add get_wallet_summary to WalletRead Sep 1, 2023
@nuttycom nuttycom force-pushed the sbs/nonlinear_sync_aware_balance branch 2 times, most recently from a4e9188 to 21815c2 Compare September 1, 2023 19:47
@nuttycom nuttycom marked this pull request as draft September 1, 2023 20:18
@nuttycom nuttycom force-pushed the sbs/nonlinear_sync_aware_balance branch from 21815c2 to add751b Compare September 1, 2023 22:19
@nuttycom nuttycom marked this pull request as ready for review September 1, 2023 22:19
@nuttycom nuttycom marked this pull request as ready for review September 5, 2023 17:39
@nuttycom nuttycom force-pushed the sbs/nonlinear_sync_aware_balance branch 3 times, most recently from 70655c9 to 73691db Compare September 5, 2023 18:38
Comment on lines +97 to +100
/// Unshielded balances are not subject to confirmation-depth constraints, because the only
/// possible operation on a transparent balance is to shield it, it is possible to create a
/// zero-conf transaction to perform that shielding, and the resulting shielded notes will be
/// subject to normal confirmation rules.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defining this to include all zero-conf funds means that an adversary will be able to arbitrarily inflate it above the realistic balance, as soon as we implement detection of zero-conf funds.

If I send you funds in a bunch of transactions that each have 50 unpaid actions and expire at the next block, I can be pretty confident that at most one (probably zero) of them will be mined. So, using this value as defined for anything opens the wallet up to the transparent equivalent of a Faerie Gold attack (and to various social engineering attacks, such as refund scams, if it is ever shown to a user). This is also a potential DoS attack on auto-shielding.

I agree that we haven't yet implemented the things that would enable these attacks, but still, it should not be defined that way.

Suggested change
/// Unshielded balances are not subject to confirmation-depth constraints, because the only
/// possible operation on a transparent balance is to shield it, it is possible to create a
/// zero-conf transaction to perform that shielding, and the resulting shielded notes will be
/// subject to normal confirmation rules.
/// Unshielded balance, with a minimum confirmation depth of 1.
///
/// The only possible operation on a transparent balance is to shield it, and the resulting
/// shielded notes will be subject to normal confirmation rules. Nevertheless, the unshielded
/// balance should not be over-reported, and including zero-conf UTXOs without restriction
/// would make it too easy for an adversary to cause such over-reporting. This policy might
/// be refined in future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zero-conf balances have essentially become the standard among zcash (and Bitcoin and Ethereum) wallets, and the functionality to provide zero-conf balance is highly in demand. I don't know how we get around that; users in general would prefer to immediately see incoming funds as being recognized, at the cost of having to be diligent about waiting for important transactions to be mined.

Copy link
Contributor

@daira daira Sep 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We spent a huge amount of time, effort, and protocol complexity preventing Faerie Gold attacks. I don't see why we would just throw up our hands and accept a transparent attack with similar impact because not caring about it is "the standard".

What do Bitcoin and Ethereum wallets do these days about minimum-relay-fee transactions that definitely won't get mined? Are you really saying they just show them as balance anyway?

@nuttycom nuttycom force-pushed the sbs/nonlinear_sync_aware_balance branch 3 times, most recently from c15fa21 to cb7a497 Compare September 5, 2023 22:04
The intent of this API is to provide a single API which returns in a
single call:

* per-account balances, including pending values
* wallet sync progress

Fixes zcash#865
Fixes zcash#900
@nuttycom nuttycom force-pushed the sbs/nonlinear_sync_aware_balance branch from cb7a497 to cc95eb1 Compare September 5, 2023 22:07
Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed in a pairing with @nuttycom, so the PR kept changing to reflect these as we went. Marking as "changes requested" and then we can check they all were addressed.

zcash_client_sqlite/src/testing.rs Outdated Show resolved Hide resolved
zcash_client_sqlite/src/wallet.rs Outdated Show resolved Hide resolved
zcash_client_sqlite/src/wallet.rs Outdated Show resolved Hide resolved
zcash_client_sqlite/src/wallet.rs Outdated Show resolved Hide resolved
zcash_client_sqlite/src/wallet.rs Outdated Show resolved Hide resolved
zcash_client_sqlite/src/wallet.rs Outdated Show resolved Hide resolved
zcash_client_sqlite/src/wallet.rs Outdated Show resolved Hide resolved
zcash_client_sqlite/src/wallet.rs Show resolved Hide resolved
@nuttycom nuttycom requested review from daira and str4d September 5, 2023 22:20
@nuttycom nuttycom force-pushed the sbs/nonlinear_sync_aware_balance branch from cc95eb1 to c29ac36 Compare September 5, 2023 22:33
@nuttycom nuttycom force-pushed the sbs/nonlinear_sync_aware_balance branch from c29ac36 to 6cbb107 Compare September 5, 2023 22:50
@nuttycom
Copy link
Contributor Author

nuttycom commented Sep 5, 2023

force-pushed to address comments from code review

str4d
str4d previously approved these changes Sep 5, 2023
Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 6cbb107


let fully_scanned_height =
block_fully_scanned(conn)?.map_or(birthday_height - 1, |m| m.block_height());
let summary_height = (chain_tip_height + 1).saturating_sub(std::cmp::max(min_confirmations, 1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a slight issue here regarding notes that are just about to expire. Without the max(_, 1), with min_confirmations == 0 this would set summary_height to the "mempool height" (chain_height + 1), which is precisely what we want for any transaction in the mempool (that still has a chance of being mined, and thus mined before expiry). Down below in the note selection code, we exclude transactions that have expired as of summary_height (because expiry_height < summary_height) from the balance, which means if someone calls this API with min_confirmations == 0, then about-to-expire funds will disappear from the wallet balance, only to reappear again if the transaction does actually get mined in the last block it can.

I'm fine with this being an edge case we don't handle yet, and instead merging @daira's suggested comment change that we treat min_confirmations == 0 as min_confirmations == 1 for shielded notes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's file an issue so that we don't forget this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed as #940.

Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-utACK 1e12e9d

@str4d str4d dismissed daira’s stale review September 6, 2023 00:04

Blocking comments addressed.

@str4d str4d merged commit 236e9f2 into zcash:main Sep 6, 2023
8 of 10 checks passed
Copy link
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Post-hoc ACK with comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants